package com.dahai.gameinfo.mapper;

import com.dahai.gameinfo.model.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;


public interface GameInfoMapper {

    @Select("update ListData set path = #{path} where id = ${id}")
    public void updateListData(ListData listData);

    @Select("select count(id) from ListData where classId = #{0}")
    public int getListDataCount(int clazz);

    @Select("select * from ListData where classId = #{0} limit #{1}, 10")
    public List<ListData> getListByClassByPage(int clazz, int page);

    @Select("select * from ListData where classId = #{clazz}")
    public List<ListData> getListByClass(int clazz);

    @Select("delete from ListData where id = #{id}")
    public void deleteGame(int id);

    @Select("select * from ListData limit 10")
    public List<ListData> getListByTypeContent();

    @Select("select * from ListData where id = #{id}")
    public List<ListData> getListById(int id);

    @Select("select * from ListData where title like #{title}")
    public List<ListData> searchGame(String title);

    /**
     * 保存数据
     */
    @Insert("insert into ListData(title, size, classId, detailUrl, info, typeContent, hot, icon) values(#{title}, #{size}, #{classId}, #{detailUrl}, #{info}, #{typeContent}, #{hot}, #{icon})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    public void save(ListData demo);

    @Select("select * from ListClass")
    public List<ListClass> getClassType();

    @Insert("insert into ListClass(name) values(#{name})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    public void addClassType(ListClass listClass);

    @Select("select * from UserSelect where userid = #{userid}")
    public List<UserSelect> getSelectListById(int userid);

    @Select("insert into UserSelect(gameid, size, date, count, userid) values(#{gameId}, #{size}, #{date}, #{count}, #{userid})")
    public void addSelect(UserSelect userSelect);

    @Insert("insert into Userinfo(openid, sessionKey, date) values(#{openid}, #{sessionKey}, #{date})")
    public void insertOrUpdateUserinfo(Userinfo userinfo);

    @Select("select * from Userinfo where openid = #{openid}")
    public List<Userinfo> getUserinfo(String openid);

    @Select("select * from LoginData where username = #{username} and password = #{password}")
    public List<LoginData> login(LoginData loginData);

    @Select("update LoginData set token = #{token} where id = #{id}")
    public void updateToken(LoginData loginData);

    @Select("select * from LoginData where id = #{id}")
    public List<LoginData> tokenId(int id);

    @Insert("insert into Userinfo(username, password) values(#{username}, #{password})")
    public void insertLoginData(LoginData userinfo);

    @Select("select * from UserSelect where id = #{id}")
    public List<UserSelect> getSelectById(int id);

    @Select("update ListData set size = #{size} where id = #{id}")
    public void updateGameSize(ListData listData);
}
